﻿package  {
	import com.kerry.camera.CameraTracer;
	import com.kerry.character.Role;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;
	
	/**
	 * com.kerry.character.Role 类的演示文件，人物行走并结合 CameraTracer （镜头跟踪）
	 * @author PhoenixKerry（http://blog.sina.com.cn/yyy98）
	 */
	public class Main extends Sprite {
		private var dirX:int = 0;
		private var dirY:int = 0;
		private var role:Role;
		private var roleTracer:CameraTracer;
		
		public function Main() {
			role = new Role(new XiaoYao(0, 0), 5, 9, 5);
			game_level.addChild(role);
			
			roleTracer = new CameraTracer(role, role.parent, stage.stageWidth, stage.stageHeight, role.width / 2, role.height / 2);
			
			stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDownHandler);
			stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUpHandler);
			addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
		}
		
		private function onEnterFrameHandler(e:Event):void {
			role.go(dirX, dirY);
			roleTracer.xTrace();
			roleTracer.yTrace();
		}
		
		private function onKeyUpHandler(e:KeyboardEvent):void {
			switch (e.keyCode) {
				case Keyboard.UP:
				case Keyboard.DOWN: dirY = 0;
				break;
				case Keyboard.LEFT:
				case Keyboard.RIGHT: dirX = 0;
			}
		}
		
		private function onKeyDownHandler(e:KeyboardEvent):void {
			switch (e.keyCode) {
				case Keyboard.UP: dirY = -1;
				break;
				case Keyboard.DOWN: dirY = 1;
				break;
				case Keyboard.LEFT: dirX = -1;
				break;
				case Keyboard.RIGHT: dirX = 1;
			}
		}
		
	}
}